package java_thinking.unit_13._13_5;

import java.io.PrintStream;
import java.util.Formatter;

/**
 * @Description : Formatter类的使用
 * @author: cww
 * @DateTime: 2019-03-24 20:53
 */

public class Turtle {
    private String name;
    /**
     * 创建Formatter对象时需要向其构造器传递告诉它最终将结果输出到哪里
     * Formatter 的构造器经过重载可以接受多重输出目的地，不过最常用的还是
     * PrintString()、OutputString和File
     */
    private Formatter f;
    public Turtle(String name,Formatter f){
        this.name = name;
        this.f = f;
    }
    public void move(int x,int y){
        f.format("%s the Turtle is at (%d,%d)\n",name,x,y);
    }

    public static void main(String[] args) {
        PrintStream outAlias = System.out;
        Formatter formatter = new Formatter(System.out);
        System.out.println("21212");
        Turtle tommy = new Turtle("Tommy",new Formatter(System.out));
        Turtle tommy1 = new Turtle("Tommy",new Formatter(System.err));
        Turtle terry = new Turtle("Terry",new Formatter(outAlias));
        tommy.move(0,0);
        tommy.move(4,8);
        terry.move(4,8);
        terry.move(3,3);
        tommy1.move(3,3);
    }
}
